package com.hdstcloud.device.service.bo;

import com.frame.base.comm.persistence.BoBaseData;
import com.frame.base.comm.persistence.ConditionMatchMode;
import com.frame.base.comm.persistence.annotaion.BoConstraint;
import com.frame.base.comm.persistence.annotaion.PersisCondition;
import com.frame.base.comm.persistence.annotaion.PersisMethod;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.List;

/**
 * 设备业务对象
 *
 * @author Dominic
 */

@PersisMethod(name = "getByDevIdAndAttrId", condtions = {
        @PersisCondition(name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS),
        @PersisCondition(obj = "attr", name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "listDevIdsForLikeAttrs", condtions = {
        @PersisCondition(obj = "attr", name = "rtValue", valType = String.class, mode = ConditionMatchMode.LIKE),
        @PersisCondition(obj = "attr.dataItemInfo", name = "id", valType = Integer.class, mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "countDevsNormal", condtions = {
        @PersisCondition(name = "id", valType = String.class, mode = ConditionMatchMode.IN),
        @PersisCondition(name = "communicateStatus", valType = Integer.class, mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "updateCommunicationAndThresholdValue", condtions = {
        @PersisCondition(name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS),
        @PersisCondition(name = "communicateStatus", valType = Integer.class, mode = ConditionMatchMode.EQUALS),
        @PersisCondition(name = "thresholdValue", valType = Integer.class, mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "updateDevCommunication", condtions = {
        @PersisCondition(name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS),
        @PersisCondition(name = "communicateStatus", valType = Integer.class, mode = ConditionMatchMode.EQUALS)
})

@PersisMethod(name = "getDevHistoryData", condtions = {
        @PersisCondition(name = "id", valType = String.class, mode = ConditionMatchMode.EQUALS)
})

@Data
@NoArgsConstructor
public class BoInfo extends BoBaseData {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "JDBC")
    private String id;//设备ID
    private String name;//设备名
    private String location;//设备位置描述
    private String searchName;//检索名称
    private Integer status;//设备业务状态
    private Integer thresholdValue;//时间阈值（单位秒 ）
    private Integer communicateStatus;//通讯状态

    @BoConstraint(dbColumn = "type", value = "1")
    private List<BoDevItem> attr;//专用属性项

    // TODO配置项和数据项暂时先冗余一份在这里，如果以后需求是对相同型号的设备进行配置不同的配置和数据项的时候再去修改代码
    @BoConstraint(dbColumn = "type", value = "2")
    private List<BoDevItem> data;//数据项

    @BoConstraint(dbColumn = "type", value = "3")
    private List<BoDevItem> config;//配置项

    /**
     * 逻辑删除字段
     */
    private Integer deleted;

    public BoInfo(String id, List<BoDevItem> data) {
        this.id = id;
        this.data = data;
    }

    public BoInfo(String id, Integer communicateStatus, Integer thresholdValue) {
        this.id = id;
        this.thresholdValue = thresholdValue;
        this.communicateStatus = communicateStatus;
    }
}